import { _decorator, Component, director, Node } from 'cc';
import { TimerManagerNode } from './TimerManagerNode';
const { ccclass, property } = _decorator;


export class TimerManager
{
    private static instance: TimerManager;
    public static get Instance():TimerManager 
    {
        if(!this.checkTimerManager())
        {
            this.instance = new TimerManager();
        }
         return this.instance;
    }

    private static checkTimerManager():boolean
    {
        let instanceCheck = TimerManager.instance != null
        if(!instanceCheck)
            return false

        let timerManagerNodeCheck = TimerManager.instance.timerManagerNode != null
        if(!timerManagerNodeCheck)
            return false

        return true
    }


    private timerManagerNode:TimerManagerNode


    public SetTimer(reference:object,time:number,callBack:()=>void):void
    {
        this.timerManagerNode.SetTimer(reference,time,callBack);
    }


    private constructor()
    {
        let node = new Node("[-----TimerManager-----]")
        this.timerManagerNode = node.addComponent(TimerManagerNode)
        director.addPersistRootNode(node);

        console.log("TimerManager 创建成功!");
    }
}


